package com.example.demo.Component;

import org.springframework.util.DigestUtils;

import java.util.UUID;

public class Salt_Encryption {
    public static String salt_first(String password){
        String salt= UUID.randomUUID().toString().replace("-","");
        String md5_password= DigestUtils.md5DigestAsHex((password+salt).getBytes());
        String final_password=salt+"$"+md5_password;
        return final_password;
    }
    public static String salt_double(String salt,String input_password){
        String md5_password= DigestUtils.md5DigestAsHex((input_password+salt).getBytes());
        String final_password=salt+"$"+md5_password;
        return final_password;
    }
    public static boolean verify(String input_password,String final_password){
        String salt=final_password.split("\\$")[0];
        String input_final_password=salt_double(salt,input_password);
        return input_final_password.equals(final_password);
    }
}

